<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: stats_customers.php 113 2013-09-21 12:08:32Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 113 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 12:08:32 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require('includes/application_top.php');
require(DIR_WS_CLASSES . 'currencies.php');
$currencies = new currencies();
require(DIR_WS_INCLUDES.'metatag.php');
?>
</head>
<body>
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<div id="wrapper">
<table class="outerTable" cellspacing="0" cellpadding="0">
  <tr>
    <td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
		<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
	</td>
    <td class="boxCenter" valign="top">
		<table border="0" width="100%" cellspacing="0" cellpadding="2">
      		<tr>
        		<td>
					<table border="0" width="100%" cellspacing="0" cellpadding="0">
						<tr>
							<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
						</tr>
					</table>
				</td>
      		</tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0" class="dataTable">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_NUMBER; ?></td>
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CUSTOMERS; ?></td>
                <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TOTAL_PURCHASED; ?>&nbsp;</td>
              </tr>
				<?php
				  if ($_GET['page'] > 1) $rows = $_GET['page'] * '20' - '20';
				  $sql = "SELECT c.customers_firstname, c.customers_lastname, sum(op.final_price) as ordersum from " . TABLE_CUSTOMERS . " c, " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS . " o WHERE c.customers_id = o.customers_id and o.orders_id = op.orders_id group by c.customers_firstname, c.customers_lastname ORDER BY ordersum DESC";
				  $query = page_break_create($_POST['per_site'], $_GET['page'], $sql, 'stats_customers.php');  
				  $customers = $query['query'];
				  $customers_query_numrows = $db->db_query("SELECT customers_id FROM " . TABLE_ORDERS . " GROUP BY customers_id");
				  $customers_query_numrows = $customers_query_numrows->_numOfRows;
				  while (!$customers->EOF) {
				    $rows++;

				    if (strlen($rows) < 2) {
				      $rows = '0' . $rows;
				    }
					if ($rows % 2 == 0)
						$f = 'dataTableRow';
					else
						$f = ''; ?>
				<tr class="<?php echo $f ?>" onmouseover="this.className='dataTableRowOver';this.style.cursor='pointer'" onmouseout="this.className='<?php echo $f ?>'" onclick="document.location.href='<?php echo href_link(FILENAME_CUSTOMERS, 'search=' . $customers->fields['customers_lastname'], 'NONSSL'); ?>'">
                	<td class="dataTableContent"><?php echo $rows; ?>.</td>
                	<td class="dataTableContent"><?php echo '<a href="' . href_link(FILENAME_CUSTOMERS, 'search=' . $customers->fields['customers_lastname'], 'NONSSL') . '">' . $customers->fields['customers_firstname'] . ' ' . $customers->fields['customers_lastname'] . '</a>'; ?></td>
                	<td class="dataTableContent" align="right"><?php echo $currencies->format($customers->fields['ordersum']); ?>&nbsp;</td>
              </tr>
			<?php
			$customers->MoveNext();
			  }
			?>
            </table></td>
          </tr>
          <tr>
            <td colspan="3"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="page_break">
				<td class="smallText" valign="top" width="33.3%"><?php echo 'Angezeigt werden '.$query['from'].' bis '.$query['to'].' (von insgesamt '.$query['total'].' Kunden)'; ?></td>
				<td class="smallText" align="center" width="33.3%"></td>
				<td class="smallText" align="right" width="33.3%">
					Kunden pro Seite: <?php echo $query['page_break']->perSiteDropdown($_GET['page']); ?>
				</td>
			</tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</div>
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>